package com.ruoyi.teacher.special.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.teacher.special.domain.School;
import com.ruoyi.teacher.special.mapper.SchoolMapper;
import com.ruoyi.teacher.special.query.SchoolQuery;
import com.ruoyi.teacher.special.service.ISchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 心理特色学校Service业务层处理
 *
 * @author duanxinli
 * @date 2023-11-03
 */
@Service
public class SchoolServiceImpl implements ISchoolService {
    @Autowired
    private SchoolMapper schoolMapper;

    /**
     * 查询心理特色学校
     *
     * @param id 心理特色学校主键
     * @return 心理特色学校
     */
    @Override
    public School selectSchoolById(String id) {
        return schoolMapper.selectSchoolById(id);
    }

    /**
     * 查询心理特色学校列表
     *
     * @param schoolQuery 心理特色学校
     * @return 心理特色学校
     */
    @Override
    public List<School> selectSchoolList(SchoolQuery schoolQuery) {
        if (schoolQuery.getDateRange() != null) {
            schoolQuery.setCreateStart(schoolQuery.getDateRange().get(0));
            schoolQuery.setCreateEnd(schoolQuery.getDateRange().get(1));
        }
        return schoolMapper.selectSchoolList(schoolQuery);
    }

    /**
     * 新增心理特色学校
     *
     * @param school 心理特色学校
     * @return 结果
     */
    @Override
    public int insertSchool(School school) {
        school.setId(IdUtils.fastUUID());
        school.setCreateDate(DateUtils.getNowDate());
        String username = SecurityUtils.getUsername();
        school.setCreateBy(username);
        school.setSort(0L);
        school.setDelFlag(0L);
        return schoolMapper.insertSchool(school);
    }

    /**
     * 修改心理特色学校
     *
     * @param school 心理特色学校
     * @return 结果
     */
    @Override
    public int updateSchool(School school) {
        return schoolMapper.updateSchool(school);
    }

    /**
     * 批量删除心理特色学校
     *
     * @param ids 需要删除的心理特色学校主键
     * @return 结果
     */
    @Override
    public int deleteSchoolByIds(String[] ids) {
        return schoolMapper.deleteSchoolByIds(ids);
    }

    /**
     * 删除心理特色学校信息
     *
     * @param id 心理特色学校主键
     * @return 结果
     */
    @Override
    public int deleteSchoolById(String id) {
        return schoolMapper.deleteSchoolById(id);
    }
}
